import React from 'react';
import ReactDOM from 'react-dom';
import CMPModal from './Modal';

// let modal = null;
let div = null;

const show = props => {
  // console.log(props);
  if (div) return false;
  div = document.createElement('div');
  document.body.appendChild(div);

  const close = () => {
    if (div) {
      ReactDOM.unmountComponentAtNode(div);
      document.body.removeChild(div);
      div = null;
    }
  };

  ReactDOM.render(<CMPModal {...props} onClose={close}></CMPModal>, div);
  // console.log(modal);
}

const Modal = {};
Modal.show = show;

export default Modal;
